//引入token
var jwt = require('jsonwebtoken');
//约定密钥
let secret = "yikesecret";

//生成token
exports.generateToken = function(id){
  let payload = {id:id,time:new Date()};
  let token = jwt.sign(payload,secret,{expiresIn:60*60*24*120});
  return token;
}

//解码token
exports.verifyToken = function(e){
  let payload = jwt.verify(e,secret,function(err,result){
    if(err){
      return 0;
    }else{
      return 1;
    }
  });
  return payload;
}
